package com.example.dapengdata.FieldMessage;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public class ViewPagerAdapter extends PagerAdapter {
    private List<View> views;
    private String TAG=ViewPagerAdapter.class.getName();
    public ViewPagerAdapter(List<View> views) {
        this.views = views;
    }
    /**
     * 获得当前界面数
     */
    @Override
    public int getCount() {
        return this.views.size();
    }

    /** 初始化position位置的界面 */
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ((ViewPager) container).addView(views.get(position));
        Log.i(TAG,"instantiateItem position:"+position);
        return views.get(position);
    }

    /**判断是否由对象生成界面*/
    @Override
    public boolean isViewFromObject(View view, Object obj) {
        return view==obj;
    }
    /***/
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        Log.i(TAG,"destroyItem position:"+position);
        ((ViewPager) container).removeView(views.get(position));
    }
}
